package 力扣;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yyq
 * @create 2022-04-26 9:07
 */
public class leetcode77 {
    public static void main(String[] args) {
        combine(3,2);
    }
    public static List<List<Integer>> combine(int n, int k) {
        List<List<Integer>> lists=new ArrayList<>();
        List<Integer> list=new ArrayList<>();


        int startIndex = 1;
        backTracking(n,k,1,list,lists);
        return lists;
    }

    private static void backTracking(int n, int k, int startindex,List<Integer> list, List<List<Integer>> lists) {
        if(list.size()==k){
            lists.add(new ArrayList<>(list));
            return;
        }

        for (int i = startindex; i <= n; i++) {
                list.add(i);
                backTracking(n,k,i+1,list,lists);
                list.remove(list.size()-1);
        }
    }
}
